// 导入koa-router模块
const Router = require('koa-router');
// 创建koa-router的实例router
const router = new Router({
    prefix: '/api'
});
const weatherControllers = require('../controllers/weather');
const prefix = '/weather'

// 定义模型 可以公用 schema $ref
/**
 * @swagger
 * definitions:
 *   weather:
 *     properties:
 *       code:
 *         type: string
 *       success:
 *         type: boolean
 *       data:
 *           properties:
 *              location:
 *                 properties:
 *                    id:
 *                      type: string
 *                      description: 城市id
 *                    name:
 *                      type: string
 *                      description: 城市名称
 *                    country:
 *                      type: string
 *                      description: 国家地区
 *                    path:
 *                      type: string
 *                      description: 城市地区
 *                    timezone:
 *                      type: string
 *                      description: 时区
 *                    timezone_offset:
 *                      type: string
 *                      description: 时差
 *              now:
 *                 properties:
 *                    text:
 *                       type: string
 *                       description: 天气现象文字
 *                    code:
 *                       type: string
 *                       description: 天气现象代码
 *                    temperature:
 *                       type: string
 *                       description: 温度，单位为c摄氏度或f华氏度
 *              last_update:
 *                 type: string
 *                 description: //数据更新时间（该城市的本地时间）
 */

/**
 * @swagger
 * /weather:
 *   get:
 *     description: 获取指定城市的当前天气情况
 *     tags: [天气模块]
 *     summary: 获取指定城市的当前天气情况
 *     produces:
 *       - application/json
 *     parameters:
 *       - name: location
 *         description: 城市名称.
 *         in: query
 *         required: false
 *     responses:
 *       200:
 *         description: 操作成功
 *         schema:
 *           type: object
 *           $ref: '#/definitions/weather'
 *   
 */
router.get(`${prefix}`, weatherControllers.getWeatherNow)


//  tags 可以理解成接口分类  parameters 参数
/**
 * @swagger
 * /weather/hours:
 *   get:
 *     description: 24小时逐小时天气预报
 *     tags: [天气模块]
 *     summary: 24小时逐小时天气预报
 *     produces:
 *       - application/json
 *     parameters:
 *       - name: location
 *         description: 所查询的位置，城市名称.
 *         in: query
 *         required: true
 *       - name: hours
 *         description: 小时数， 默认24小时.
 *         in: query
 *         required: false
 *       - name: start
 *         description: 起始时间（0 代表这个小时，1 代表下个小时）.
 *         in: query
 *         required: false
 *     responses:
 *       200:
 *         description: 操作成功
 *         schema:
 *           type: object
 *           $ref: '#/definitions/weather'
 *   
 */
router.get(`${prefix}/hours`, weatherControllers.getWeatherHours)

/**
 * @swagger
 * /weather/daily:
 *   get:
 *     description: 未来15天逐日天气预报和昨日天气
 *     tags: [天气模块]
 *     summary: 未来15天逐日天气预报和昨日天气
 *     produces:
 *       - application/json
 *     parameters:
 *       - name: location
 *         description: 所查询的位置，城市名称.
 *         in: query
 *         required: true
 *       - name: days
 *         description: 天数， 默认最多3天.
 *         in: query
 *         required: false
 *       - name: start
 *         description: 起始天数（权限允许的最多天数）.
 *         in: query
 *         required: false
 *     responses:
 *       200:
 *         description: 操作成功
 *         schema:
 *           type: object
 *           $ref: '#/definitions/weather'
 *   
 */
router.get(`${prefix}/daily`, weatherControllers.getWeatherDaily)


/**
 * @swagger
 * /weather/alarm:
 *   get:
 *     description: 气象灾害预警
 *     tags: [天气模块]
 *     summary: 气象灾害预警
 *     produces:
 *       - application/json
 *     parameters:
 *       - name: location
 *         description: 所查询的位置，城市名称.
 *         in: query
 *         required: true
 *       - name: detail
 *         description: 是否返回预警ID.
 *         in: query
 *         required: false
 *     responses:
 *       200:
 *         description: 操作成功
 *         schema:
 *           type: object
 *           $ref: '#/definitions/weather'
 *   
 */
router.get(`${prefix}/alarm`, weatherControllers.getWeatherAlarm)

/**
 * @swagger
 * /weather/life:
 *   get:
 *     description: 生活指数
 *     tags: [天气模块]
 *     summary: 生活指数
 *     produces:
 *       - application/json
 *     parameters:
 *       - name: location
 *         description: 所查询的位置，城市名称.
 *         in: query
 *         required: true
 *     responses:
 *       200:
 *         description: 操作成功
 *         schema:
 *           type: object
 *           $ref: '#/definitions/weather'
 *   
 */
router.get(`${prefix}/life`, weatherControllers.getWeatherLifeSuggestion)

/**
 * @swagger
 * /weather/hweather/now:
 *   get:
 *     description: 和风天气
 *     tags: [天气模块]
 *     summary: 和风天气
 *     produces:
 *       - application/json
 *     parameters:
 *       - name: location
 *         description: 所查询的位置，城市名称.
 *         in: query
 *         required: false
 *     responses:
 *       200:
 *         description: 操作成功
 *         schema:
 *           type: object
 *           $ref: '#/definitions/weather'
 *   
 */
router.get(`${prefix}/hweather/now`, weatherControllers.initDay)

/**
 * @swagger
 * /weather/hweather/day/detail:
 *   get:
 *     description: 和风天气获取详情信息
 *     tags: [天气模块]
 *     summary: 和风天气获取详情信息
 *     produces:
 *       - application/json
 *     parameters:
 *       - name: location
 *         description: 所查询的位置，城市名称.
 *         in: query
 *         required: false
 *     responses:
 *       200:
 *         description: 操作成功
 *         schema:
 *           type: object
 *           $ref: '#/definitions/weather'
 *   
 */
router.get(`${prefix}/hweather/day/detail`, weatherControllers.initDayDetail)

/**
 * @swagger
 * /weather/hweather/search:
 *   get:
 *     description: 和风天气城市名称
 *     tags: [天气模块]
 *     summary: 和风天气城市名称
 *     produces:
 *       - application/json
 *     parameters:
 *       - name: location
 *         description: 所查询的位置，城市名称.
 *         in: query
 *         required: true
 *     responses:
 *       200:
 *         description: 操作成功
 *         schema:
 *           type: object
 *           $ref: '#/definitions/weather'
 *   
 */
router.get(`${prefix}/hweather/search`, weatherControllers.searchCity)
module.exports = router